import createPersistedState from 'vuex-persistedstate'
import * as Cookies from "js-cookie"
//引入js-cookilet 
const cookieStorage = {
    getItem: function(key) {
        return Cookies.getJSON(key);
    },
    setItem: function(key, value) {
        return Cookies.set(key, value, {expires: 3, secure: false});
    },
    removeItem: function(key) {
        return Cookies.remove(key);
    }
};
//vuex采用modules模式，只保存app moudle中的state
export default (context) => {
  createPersistedState({
    storage: cookieStorage,
    getState: cookieStorage.getItem,
    setState: cookieStorage.setItem,
    reducer(val){
      return {
        app: val.app    //保存app module中的state，一定要key+value形式
      };
    }
  })(context.store);
};